package com.wuze.cloud.controller;

import com.wuze.cloud.request.SysCreateFolderQuery;
import com.wuze.cloud.request.SysDownloadQuery;
import com.wuze.cloud.request.SysFolderQuery;
import com.wuze.cloud.request.SysUpdateFolderQuery;
import com.wuze.cloud.response.SysFolderListResponse;
import com.wuze.cloud.response.SysFolderResponse;
import com.wuze.cloud.response.SysFolderVO;
import com.wuze.cloud.result.Result;
import com.wuze.cloud.service.SysFolderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @author: wuze
 * @description:
 * @date: 2023/02/18
 */
@RestController
public class SysFolderController {

    public static final String PREFIX_PATH = "/sys/folder/";

    @Autowired
    private SysFolderService folderService;

    @PostMapping(PREFIX_PATH+"findByPage/v1")
    public Result<SysFolderResponse> findByPage(@Validated @RequestBody SysFolderQuery query){
        return Result.success(folderService.findByPage(query));
    }

    @PostMapping(PREFIX_PATH+"findList/v1")
    public Result<List<SysFolderVO>> findList(@RequestBody SysFolderQuery query){
        return Result.success(folderService.findList(query));
    }

    @PostMapping(PREFIX_PATH+"findList/v2")
    public Result<SysFolderListResponse> findListv2(@RequestBody SysFolderQuery query){
        return Result.success(folderService.findListv2(query));
    }

    @PostMapping(PREFIX_PATH+"findRecyclingByPage/v1")
    public Result<SysFolderResponse> findRecyclingByPage(@Validated @RequestBody SysFolderQuery query){

        return Result.success(folderService.findByPage(query));
    }

    @PostMapping(PREFIX_PATH+"createFolder/v1")
    public Result<Boolean> add(@Validated @RequestBody SysCreateFolderQuery query){
        folderService.add(query);
        return Result.success(Boolean.TRUE);
    }

    @PostMapping(PREFIX_PATH+"updateFolder/v1")
    public Result<Boolean> update(@Validated @RequestBody SysUpdateFolderQuery query){
        folderService.update(query);
        return Result.success(Boolean.TRUE);
    }

    @PostMapping(PREFIX_PATH+"batchDownload/v1")
    public Result<Boolean> batchDownload(@RequestBody SysDownloadQuery query, HttpServletResponse response){
        folderService.batchDownload(query, response);
        return Result.success(Boolean.TRUE);
    }

}
